]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
st: Add support for font-feature-settings
authorRyan Hendrickson <ryan.hendrickson@alum.mit.edu>
Thu, 17 May 2018 14:45:02 +0000 (10:45 -0400)
committerFlorian Müllner <fmuellner@gnome.org>
Fri, 8 Jun 2018 16:45:07 +0000 (18:45 +0200)
Cantarell now supports tabular figures, which are useful in places
where digits should either align or not use different widths. In
order to allow elements to request the feature, add support for
the corresponding CSS property[0].

[0] https://www.w3.org/TR/css-fonts-3/#font-rend-desc

https://gitlab.gnome.org/GNOME/gnome-shell/issues/34

src/st/st-private.c
src/st/st-theme-node.c
src/st/st-theme-node.h
src/st/test-theme.c
src/st/test-theme.css

index a0100e0945c6f32fa8cdbf951320e8c188ecbf61..882c2631e1ab0646ea82f6f0d1b3b272b453b4fe 100644 (file)
@@ -117,6 +117,7 @@ _st_set_text_from_style (ClutterText *text,
   const PangoFontDescription *font;
   StTextAlign align;
   gdouble spacing;
+  gchar *font_features;
 
   st_theme_node_get_foreground_color (theme_node, &color);
   clutter_text_set_color (text, &color);
@@ -151,6 +152,13 @@ _st_set_text_from_style (ClutterText *text,
       pango_attr_list_insert (attribs, letter_spacing);
     }
 
+  font_features = st_theme_node_get_font_features (theme_node);
+  if (font_features)
+    {
+      pango_attr_list_insert (attribs, pango_attr_font_features_new (font_features));
+      g_free (font_features);
+    }
+
   clutter_text_set_attributes (text, attribs);
 
   if (attribs)
index fd2cdb084b8cd72f64be4aa44338b7f6c0c5dac3..69a0848af3b54ea2c0f3dc4a0643a54917f0475d 100644 (file)
@@ -3019,6 +3019,39 @@ st_theme_node_get_font (StThemeNode *node)
   return node->font_desc;
 }
 
+gchar *
+st_theme_node_get_font_features (StThemeNode *node)
+{
+  int i;
+
+  ensure_properties (node);
+
+  for (i = node->n_properties - 1; i >= 0; i--)
+    {
+      CRDeclaration *decl = node->properties[i];
+
+      if (strcmp (decl->property->stryng->str, "font-feature-settings") == 0)
+        {
+          CRTerm *term = decl->value;
+
+          if (!term->next && term->type == TERM_IDENT)
+            {
+              gchar *ident = term->content.str->stryng->str;
+
+              if (strcmp (ident, "inherit") == 0)
+                break;
+
+              if (strcmp (ident, "normal") == 0)
+                return NULL;
+            }
+
+          return (gchar *)cr_term_to_string (term);
+        }
+    }
+
+  return node->parent_node ? st_theme_node_get_font_features (node->parent_node) : NULL;
+}
+
 /**
  * st_theme_node_get_border_image:
  * @node: a #StThemeNode
index 08648e68af3611ca984ca90fe01112d506bbc492..e71c1d5227277d36dfd97c6535becf96a396dbe9 100644 (file)
@@ -232,6 +232,8 @@ double st_theme_node_get_letter_spacing (StThemeNode *node);
  */
 const PangoFontDescription *st_theme_node_get_font (StThemeNode *node);
 
+gchar *st_theme_node_get_font_features (StThemeNode *node);
+
 StBorderImage *st_theme_node_get_border_image (StThemeNode *node);
 StShadow      *st_theme_node_get_box_shadow   (StThemeNode *node);
 StShadow      *st_theme_node_get_text_shadow  (StThemeNode *node);
index dfc26a5e941b1399ccc89cffffa2e1990e856913..225b95fc5e49488137568e31c9937b97213ebc6e 100644 (file)
@@ -59,6 +59,24 @@ assert_font (StThemeNode *node,
   g_free (value);
 }
 
+static void
+assert_font_features (StThemeNode *node,
+                      const char  *node_description,
+                      const char  *expected)
+{
+  char *value = st_theme_node_get_font_features (node);
+
+  if (g_strcmp0 (expected, value) != 0)
+    {
+      g_print ("%s: %s.font-feature-settings: expected: %s, got: %s\n",
+               test, node_description, expected, value);
+      fail = TRUE;
+    }
+
+  if (value)
+    g_free (value);
+}
+
 static char *
 text_decoration_to_string (StTextDecoration decoration)
 {
@@ -413,6 +431,22 @@ test_font (void)
   assert_font (text3,  "text3",  "serif Bold Oblique Small-Caps 24px");
 }
 
+static void
+test_font_features (void)
+{
+  test = "font_features";
+  /* group1 has font-feature-settings: "tnum" */
+  assert_font_features (group1, "group1", "\"tnum\"");
+  /* text2 should inherit from group1 */
+  assert_font_features (text2,  "text2", "\"tnum\"");
+  /* group2 has font-feature-settings: "tnum", "zero" */
+  assert_font_features (group2, "group2", "\"tnum\", \"zero\"");
+  /* text3 should inherit from group2 using the inherit keyword */
+  assert_font_features (text3,  "text3",  "\"tnum\", \"zero\"");
+  /* text4 has font-feature-settings: normal */
+  assert_font_features (text4,  "text4",  NULL);
+}
+
 static void
 test_pseudo_class (void)
 {
@@ -554,6 +588,7 @@ main (int argc, char **argv)
   test_border ();
   test_background ();
   test_font ();
+  test_font_features ();
   test_pseudo_class ();
   test_inline_style ();
 
index 0c0af1b068b706211f66b0f3c7522d6879e88c42..d1816648decbbb26f466061c7f15bc16bbcec356 100644 (file)
@@ -13,6 +13,8 @@ stage {
     margin-left: 1in;
 
     background: #ff0000 url('some-background.png');
+
+    font-feature-settings: "tnum";
 }
 
 #text1 {
@@ -35,6 +37,7 @@ ClutterTexture.special-text {
 
 #group2 {
     font: italic 12px serif;
+    font-feature-settings: "tnum", "zero";
 }
 
 #text3 {
@@ -42,6 +45,11 @@ ClutterTexture.special-text {
     font-weight: bold;
     font-style: oblique;
     font-size: 200%;
+    font-feature-settings: "pnum";
+}
+
+#text4 {
+    font-feature-settings: normal;
 }
 
 ClutterTexture {
@@ -60,6 +68,10 @@ stage > #text2 {
     color: #ff0000;
 }
 
+#group2 > #text3 {
+    font-feature-settings: inherit;
+}
+
 #group2 {
     background-image: url('other-background.png');
     padding: 1px 2px 3px 4px;